<style>

#BOMComponents span.error {
    position: absolute !important;
    left:148px;
}

#BOMComponents tr td div {
    height: 29px;
    padding-top: 3px;
}

.quantityError{
    border-color:#e9573f;
}

.quantityInput{
     border-color: #d9dfe5;
}

#BOMComponents input.readonly{
    background:#fff !important;
    border-width:0px;
}
 
#BOMComponents .selected input.textInput{
    background:#d2eafa !important;
}

 
</style>
<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<form method="post" action="${rc.getContextPath()}/manage/bom/saveBOM" class="pageForm required-validate" onsubmit="return bom.tsubmit(this);">
    <div class="pageContent">
        <div class="pageFormContent"  >
        <input type="hidden" name="navTabId" value="${navTabId!''}">
        <input type="hidden" name="id" value="<#if (wcStandardCapacity.workCenterCode)??>${wcStandardCapacity.workCenterCode!''}</#if>">
        <fieldSet>
            <dl>
                <dt><@label key="bomCode.C,colon">物料清单编号：</@label></dt>
                <dd>
                    <input type="text" maxlength="20" name="bomCode" value="${condition.bomCode!''}" class="required  alphanumeric toUp" remote="${rc.getContextPath()}/manage/bom/checkBomCode">
                </dd>
            </dl>
            <dl>
                <dt><@label key="description.C,colon">描述：</@label></dt>
                <dd>
                    <input type="text"  maxlength="60" name="bomText" value="${condition.bomText!''}" class="required"/>
                </dd>
            </dl>
            <dl>
                    <dt>&nbsp;</dt>
                    <dd>
                        <label><input type="checkbox" name="lockFlag" value="1"><@label key="lock.C">锁定</@label></label>
                    </dd>
                </dl>
        </fieldSet>
        <div class="panel" style="width:600px;border-top:1px solid #d8dfe5;">
                    <div>
                        <div class="pBar">
                            <ul class="toolBar">
                                <li>
                                    <a class="add" width="700" height="450" href="${rc.getContextPath()}/manage/material/componentLookUpForBOM"  rel="selectMaterialCodeForBOM"
                                         lookupGroup="materialGrpId" callback="bom.appendComponents" title="<@label key='addBOMComponent.D'>新增物料清单组件</@label>"><span>
                                        <@label key='add.B'>新增</@label></span> 
                                    </a>
                                </li>
                                <li>
                                    <a class="delete" href="javascript:void(0):"  onclick="bom.deleteTr()"><span><@label key="delete.B">删除</@label></span> </a>
                                </li>
                            </ul>
                        </div>
                        <table id="BOMComponentTable" class="table border canopration" width="100%" layoutH="230">
                            <thead>
                                <tr class="theadTr">
                                    <th width="30"><input group="ids" type="checkbox" class="checkboxCtrl"></th>
                                    <th width="100"><@label key="bomComponentCode.C">组件编号</@label></th>
                                    <th width="100"><@label key="bomComponentText.C">组件描述</@label></th>
                                    <th width="100"><@label key="quantity.C">数量</@label></th>
                                </tr>
                            </thead>
                            <tbody id="BOMComponents">
                            </tbody>
                        </table>
                    </div>
            </div> 
        
    <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive" id="save">
                        <div class="buttonContent">
                            <button type="submit"><@label key="save.B">保存</@label></button>
                        </div>
                    </div>
                    </li>
                <li>
                    <div class="buttonActiveGrey">
                        <div class="buttonContent">
                            <button type="button" class="close">
                                    <@label key="close.B">关闭</@label>
                            </button>
                        </div>
                    </div>
                </li>
            </ul>
    </div>
    
<script>
    var $dialog=$.pdialog.getCurrent();
    var $tbody=$("#BOMComponents",$dialog);
    var $table=$("#BOMComponentTable",$dialog);
    var trNum=$tbody.find("tr").length;
    gridTh=$table.find("tr.theadTr th");
    var bom={
            getTrHtml:function(index,code,text){
                return '<tr>'
                +'<td style="width:'+$(gridTh[0]).width()+'px;"><div><input name="ids" type="checkbox" class="checkboxCtrl"/></div></td>'
                +'<td style="width:'+$(gridTh[1]).width()+'px;"><div><input id="'+code+'" name="components['+index+'].componentCode" readonly="readonly" type="text" class="textInput readonly"  value="'+code+'" /></div></td>'
                +'<td style="width:'+$(gridTh[2]).width()+'px;"><div>'+text+'</div></td>'
                +'<td style="width:'+$(gridTh[3]).width()+'px;"><div><input name="components['+index+'].quantity" type="text" class="textInput required quantityInput" min="1" maxlength="12"/></div></td>'
                +'</tr>';
                
            },
            appendComponents:function(data){
                var componentCodes=data.materialCode.split(',');
                var componentTexts=data.materialText.split(',');
                var html="";
                $.each(componentCodes,function(i){
                    
                    if($tbody.find("#"+componentCodes[i]).length===0)
                    {
                        $tbody.append(bom.getTrHtml(trNum,componentCodes[i],componentTexts[i]));
                        trNum++;
                    }
                });
            },
            deleteTr:function(){
            	var count = 0;
            	$tbody.find("input:checked").each(function(i){
                   count++;
                });
        	    if (count == 0) {
        	        alertMsg.warn('<@label key="selected_first.C,component.C">请选择组件！</@label>!')
        	    }else{
        	    alertMsg.confirm("<@label key='delete_sure.D,'>确定要删除？</@label>?", {
    	            okCall : function() {
    	            	   $tbody.find("input:checked").each(function(i){
    	                       $(this).parents("tr").remove();
    	                   })
    	            }
    	        });}
             
            },
            tsubmit : function(t) {
                var $form = $(t);
                if (!$form.valid()) {
                    return false;
                }
                /* if(!valid1){
                     alertMsg.warn("<@label key='lowerQuantityOrUpperQuantityAllowsLessThanOne.C'>只能有一行允许上限量或下限量为空！</@label>");
                    return false; 
                } */
                return validateCallback(t, dialogAjaxDone);
            }
            
    }
    


</script>            
            